/**
 * 用户档案里面项目列表
 */

function certificate_info(){
    var _this = this;
    var page;
    _this.page_size = 4;
    _this.pageNum = 1;

    _this.init = function(page_person){
        page = page_person;
        _this.getSubjects();
    };

    //主题展示
    admin_index.getSubjects = function (pageNum) {
        var url = appPath + "/admin/train_subject/subject_list";
        if (pageNum) {
            pageNum = pageNum;
        }
        var params = {
            'pageSize': 4,
            'pageNum':pageNum
        };
        $.ajax({
            url: url,
            data: params,
            type: "post",
            dataType: "json",
            success: function (rs) {
                var data = rs['result'];
                var dataList = data['dataList'];
                //var length = $("#subjects").parent().find("th").length;
                /*if(dataList.length<1){
                    $("#"+_this.tbody_id).empty().html(_this.noList(length));$("#"+_this.page_id).empty();return
                }*/
                var inner = list(dataList);

                // 计算分页
                var page = data['page']; // 当前页数
                var pageSize = data['pageSize']; // 每页数量
                var count = data['count']; // 总条数
                var totalPages = data['totalPages']; // 总页数
                var haveNext = data['haveNext']; // 是否有下一页
                var nextPage = data['nextPage']; // 下一页页数
                var havePre = data['havePre']; // 是否有上一页
                var prePage = data['prePage']; // 上一页页数

                if (page == 1) {
                    inner += "<a href='javascript:;' class='left icon_btn' style='display: none;'>左按钮</a>";
                } else {
                    inner += "<a href='javascript:;' class='left icon_btn'>左按钮</a>";
                }
                if (havePre == 0) {
                    inner += "<a href='javascript:;' class='left icon_btn' style='display: none;'>左按钮 </a>";
                } else {
                    inner += "<a href=\"javascript:admin_index.getSubjects(" + (page - 1) + ");\" class='left icon_btn'>左按钮 </a>";
                }
                if (haveNext == 1) {
                    inner += "<a href=\"javascript:admin_index.getSubjects(" + (page + 1) + ");\" class='right icon_btn'>右按钮 </a>";
                } else {
                    inner += "<a  class='right icon_btn' style='display: none;'>右按钮  </a>";
                }
                //console.log(inner)
                // 渲染表单
                $(".list_container").empty().html(inner);

            }
        });
    }

    list = function (dataList) {
        var len = dataList.length;
        var inner = "<ul class='clearfix'>", item;
        inner += '<li class="first">' +
            '<div class="show_img">' +
            '<img src="' + appPath + '/static/global/images/v2/no-project.png" alt="">' +
            /*'<span class="enter">点击进入</span>'+*/
            /*'<div class="show_div">' +
                '<div class="show_div_bg"></div>' +
            '</div>'+*/

            /*'<p>无主题<span class="show_line"></span></p>' +*/
            '</div>' +
            '<div class="title">' +
            '<img src="' + appPath + '/static/global/images/v2/title_info_icon.png" alt="">' +
            '<div class="title_1"><b>从业人员<i>自定义培训</i></b></div>' +
            '<div class="title_2">(您可以在此自定义培训内容)</div>' +
            '</div>' +
            '<div class="create">' +
            '<div class="options">' +
            '<div class="option" data-projectdId="1" onclick="admin_index.select(this)"><span>TRAINING</span>培训</div>' +
            '<div class="option" data-projectdId="2" onclick="admin_index.select(this)"><span>EXERCISE</span>练习</div>' +
            '<div class="option" data-projectdId="3" onclick="admin_index.select(this)"><span>EXAM</span>考试</div>' +
            '</div>' +
            '<button class="create_btn" id="btn_project_create" onclick="admin_index.createProject(this)">创建</button>' +
            '</div>' +
            "</li>";


        // 组装数据
        for (var i = 0; i < len; i++) {
            item = dataList[i];
            if (null == item.varSubjectDesc) {
                item.varSubjectDesc = ""
            }
            var temp_logo = appPath + "/static/global/images/subject_image/subject_image_" + parseInt(Math.round(Math.random())) + ".png";
            /*if("" == item.logo){
                item.logo = appPath + "/static/global/images/subject_image/subject_image_"+ parseInt(Math.round(Math.random())) +".png";
            }*/
            inner += '<li>' +
                '<div class="show_img">' +
                '<img alt="" class="lazy lazy_img" src="' + item.logo + '" onerror="admin_index.imgError(this)" >' +

                /*'<div class="show_div">' +
                  '<div class="show_div_bg"></div>' +

                    '<p>'+item.subjectDesc+'<span class="show_line"></span></p></div>'+*/

                '</div>' +
                '<div class="title">' + item.varSubjectName + '</div>' +
                '<div class="create">' +
                '<div class="options">' +
                '<div class="option" data-projectdId="1" onclick="admin_index.select(this)"><span>TRAINING</span>培训</div>' +
                '<div class="option" data-projectdId="2" onclick="admin_index.select(this)"><span>EXERCISE</span>练习</div>' +
                '<div class="option" data-projectdId="3" onclick="admin_index.select(this)"><span>EXAM</span>考试</div>' +
                '</div>' +
                '<button class="create_btn" id="btn_project_create" data-subjectId="' + item.intTrainSubjectId + '" data-subjectName="' + item.varSubjectName + '" onclick="admin_index.createProject(this)" >创建</button>' +
                '</div>' +
                "</li>";
        }
        inner += '<script>' +
            '$("img.lazy").lazyload({effect: "fadeIn"});' +
            '</script>'
        inner += "</ul>"
        //console.log(inner)
        return inner;

    }


    _this.search = function(){
        $("#courseName").val($.trim($("#courseName").val()));
        _this.initTable();
    };

    _this.searchAll = function(){
        $("#courseName").val("");
        _this.initTable();
    };

    _this.ajax = function(url, param) {
        var result;
        $.ajax({
            url : url,
            async : false,
            type : 'post',
            data : param,
            success : function(data) {
                result = data;
            }
        });
        return result;
    };
}

var study_self_info = new study_self_info();